import * as types from './types'
import axios from '../common/js/http'
export default {
    HEADER_SHOW: ({
        commit
    }) => {
        commit(types.HEADER_SHOW);
    },
    FOOTER_HIDE: ({
        commit
    }) => {
        commit(types.FOOTER_HIDE);
    },
    HEADER_HIDE: ({
        commit
    }) => {
        commit(types.HEADER_HIDE);
    },



    SET_BANKED_DATA: ({
        commit
    }, { obj }) => {
        commit(types.SET_BANKED_DATA, obj);
    },
    SET_ISLOGIN: ({
        commit
    }, { boolean }) => {
        commit(types.SET_ISLOGIN, boolean);
    },

    SET_SERVICE:({
        commit
    }, { String }) => {
        commit(types.SET_SERVICE, String);
    },
    SET_PLATFORM_CONFIG:({
        commit
    }, { obj }) => {
        commit(types.SET_PLATFORM_CONFIG, obj);
    },
    SET_CASINO_SWITCH:({
        commit
    }, { obj }) => {
        commit(types.SET_CASINO_SWITCH, obj);
    },
    SET_HEADER_FOOTER: ({
        commit
    }, { obj }) => {
        commit(types.SET_HEADER_FOOTER, obj);
    },
    SET_USER_INFO_DATA: ({commit},{Obj}) => {
        if(!localStorage.getItem("token") || localStorage.getItem("token") && JSON.stringify(Obj) != "{}"){
            if (!Obj) {
                commit(types.SET_USER_INFO_DATA, {}); 
            } else {
                commit(types.SET_USER_INFO_DATA, Obj); 
            }
            // commit(types.SET_USER_INFO_DATA, Obj);
            return false;
        }
        //处理异步请求的
        return new Promise((resolve) => {
            axios.post(axios.defaults.baseURL + '?m=api&c=user&a=userInfo',{'token':localStorage.getItem("token")}).then(function(res){
                commit(types.SET_USER_INFO_DATA, res.data.data);
                //   resolve(res);
            })
        })
    },
    SET_ACCOUNT_DATA: ({commit},{Obj}) => {
        if(!localStorage.getItem("token") || localStorage.getItem("token") && JSON.stringify(Obj) != "{}"){
            commit(types.SET_ACCOUNT_DATA, Obj); 
            return false;
        }
        //处理异步请求的
        return new Promise((resolve) => {
            axios.post(axios.defaults.baseURL + '?m=api&c=account&a=index',{'token':localStorage.getItem("token")}).then(function(res){
                commit(types.SET_ACCOUNT_DATA, res.data);
                //   resolve(res);
            })
        })
    },
    SET_USER_DATA: ({
        commit
    }, { obj }) => {
        commit(types.SET_USER_DATA, obj);
    },
}


// WEBPACK FOOTER //
// ./src/store1/actions.js